<!--
 * @Author: 1453937336@qq.com 1453937336@qq.com
 * @Date: 2024-05-11 14:45:49
 * @LastEditors: 1453937336@qq.com 1453937336@qq.com
 * @LastEditTime: 2024-06-18 15:07:00
 * @FilePath: \itforce-hris\src\components\download\index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class=''>
    <a-button @click="handleExport()"><i class="fa fa-download" /></a-button>
  </div>
</template>

<script setup lang='ts'>
import { ref, reactive, toRefs, onBeforeMount, onMounted, watchEffect, computed } from 'vue';
// 后期再将download方法复用 先暂时保留handleExport方法
import { download } from '@/utils/common/common'
let data = ref({})
const props = defineProps({
  fileName: { type: String, default: '' },
  filePath: { type: String, default: '' }
});
const handleExport = () => {
  let link = document.createElement('a');
  let url = props.filePath;
  // 这里是将url转成blob地址
  fetch(url).then(res => res.blob()).then(blob => {
    link.href = URL.createObjectURL(blob);
    // consolelog(link.href);
    link.style.display = 'none';
    link.download = props.fileName;
    link.click();
  });
}

onBeforeMount(() => {
  //// consolelog('2.组件挂载页面之前执行----onBeforeMount')
})
onMounted(() => {
  //// consolelog('3.-组件挂载到页面之后执行-------onMounted')
})
watchEffect(() => {
})
</script>
<style scoped lang='scss'></style>